#ifndef H_RCGD_OCXO_H
#define H_RCGD_OCXO_H

#define		ID_MODE_FREQ	0
#define		ID_MODE_DAC		1

#define		ID_MODE_CURRENT	2
#define		ID_MODE_SLOPE   3

/*
#define	DEC_Intercept	10E13
#define DEC_Slope		10E15
#define DEC_Temperature 100

#define ID_TABLE_SIZE	12


typedef struct TempTable_S{

	int	Temperature;
	int	Yintercept;
	int	Slope;

} TempTable_;

typedef struct fTempTable_S{

	float	Temperature;
	double	Yintercept;
	double	Slope;

} fTempTable_;

typedef struct ID_Table_S{

	TempTable_	Table[ID_TABLE_SIZE];

} ID_Table_;

*/




#define	DEC_Intercept	10E13
#define DEC_Slope		10E15
#define DEC_Temperature 100

#define MAX_ID_TABLE_SIZE	15

#define KERNEL_INFO_SIZE 512
#define KERNEL_DATA_SIZE	(KERNEL_INFO_SIZE-4)/2

#define PC_PROGRAM_HEADER 2

typedef struct KernalInfo_s
{
	//kang unsigned short Header;//2byte
	unsigned int Header;//4byte kang
	//kang unsigned short data[KERNEL_DATA_SIZE];
	unsigned short data[127];
	unsigned short CRC16;//2byte
}KernalInfo_;


typedef struct OCXO_ID_S{

    double 	TDAC;
	char	Valid;
	char	mode;
	char	id_str[10];

    unsigned short Buffer[128];
    char	Buffer_flag;

} OCXO_ID_;


typedef struct TempTable_S{

	int	Temperature;
	int	Yintercept;
	int	Slope;

} TempTable_;

typedef struct fTempTable_S{

	float	Temperature;
	double	Yintercept;
	double	Slope;

} fTempTable_;

typedef struct ID_Table_S{

	char		NAME[12];
	short		mode;

	WORD		TableNo;
	TempTable_	Table[MAX_ID_TABLE_SIZE];

} ID_Table_;


#define CGM_Rubidium_OSC	0
#define CGM_OCXO_OSC		1

#define Rubidium_OSC	2
#define OCXO_OSC		3


typedef struct {
	char exist;
	char status;
	char kind;
} OSC_;



extern char id_mode;

extern OSC_	OSC;
extern void Init_OSC(void);

extern char read_temp_id(void); //kang
void Init_OCXO_ID(void);
void Setting_OCXOID(void);


////////////////TGain
typedef struct
{
	int t; // time .. 1 means 1 sec
	int T; // temperature 10 means 1 degree celsius
	int dac; // dac value
	int offset ; // timing offset 10 means 100ns
}stTGainData_;

#define M_stTGainData_Size 100    	//data gathering time will be 60*10*100
#define M_stTGainData_Interval 490   //data gathering time will be 60*10*100
//#define M_stTGainData_Size 100    //data gathering time will be 60*10*100
typedef struct
{
	int first; // for initialization, used only once
	stTGainData_ d[M_stTGainData_Size];
	int i; //index of array , i = i%M_stTGainData_Size
	int cnt; //input size

	stTGainData_ dPrev;
	int Tmin; //input size
	int Tmax; //input size
	int OFFSETmin; //input size
	int OFFSETmax; //input size
	int TGain;
} stTGain_;

extern stTGain_ TempGain;

void TGainPush(stTGainData_ *pp);
int TGainDisplay();
void TGainCalc(int );
void TGainPushEach(int t, int T, int dac, int offset);
extern int bTGainDisply;

#endif
